package com.itboye.mengwu.app.ui.aiwujia;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Observable;
import java.util.Observer;

import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.BitmapDrawable;
import android.os.Handler;
import android.os.Message;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.AbsListView;
import android.widget.AbsListView.OnScrollListener;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemLongClickListener;
import android.widget.LinearLayout.LayoutParams;
import android.widget.FrameLayout;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.itboye.app.service.util.DataLoaderthree;
import com.itboye.app.service.util.DataLoaderthree.OnCompletedListener;
import com.itboye.app.service.util.FooterViewtwo;
import com.itboye.app.service.util.ItemAdapterOne;
import com.itboye.core.alert.ByAlert;
import com.itboye.core.object.BaseFragment;
import com.itboye.core.object.ResultEntity;
import com.itboye.core.object.SpPublicParams;
import com.itboye.core.utils.SPUtils;
import com.itboye.mengwu.R;
import com.itboye.mengwu.address.AddressSelectView;
import com.itboye.mengwu.address.AddressSelectView2;
import com.itboye.mengwu.app.MainApplication;
import com.itboye.mengwu.app.adapter.Item2Adapter;
import com.itboye.mengwu.app.adapter.ItemAdapter;
import com.itboye.mengwu.app.ui.mymeng.NewPingHUiTie;
import com.itboye.mengwu.app.ui.mymeng.ZengActivity;
import com.itboye.mengwu.data.model.LunBoModel;
import com.itboye.mengwu.data.model.LuntanTieZiBean;
import com.itboye.mengwu.data.model.MaMaZengFaBuFenLeiBean;
import com.itboye.mengwu.data.model.TieZiBaoHanReply;
import com.itboye.mengwu.data.model.TieZiBaoHanReplyBaoBaoLe;
import com.itboye.mengwu.data.model.TieZiModel;
import com.itboye.mengwu.data.model.WodeZengSongShangPingBean;
import com.itboye.mengwu.data.presenter.NewMaMaZengPresenter;
import com.itboye.mengwu.data.presenter.TieZiPresenter;
import com.itboye.mengwu.widget.MyListener;
import com.itboye.mengwu.widget.PullToRefreshLayout;
import com.itboye.mengwu.widget.PullableGridView;
import com.itboye.mengwu.widget.PullToRefreshLayout.OnRefreshListener;

public class ZengSongListFragment extends BaseFragment implements Observer,
		OnClickListener {

	private PullableGridView zengsong_list_gv;
	private DataLoaderthree loader;
	private int page = 1;
	public final static int PAGE_SIZE = 10; // 每次加载10个item
	private final static int COUNT = 60;// 最多加载215个，确定加载数。
	private ItemAdapterOne adapter;
	private List<String> list = new ArrayList<String>();
	private boolean isLoadFinished;
	private HashMap<String, String> loaderMap = new HashMap<String, String>();
	RelativeLayout quyuLayout, fenleiLayout, paixuLayout;
	FrameLayout jumpWindow;

	private PopupWindow popupWindow;

	private NewMaMaZengPresenter newMaMaZengPresenter;
	WodeZengSongShangPingBean wodeZengSongShangPingBean,
			wodeZengSongShangPingBeanTwo;
	PullToRefreshLayout refresh_view;
	LuntanTieZiBean luntanTieZiBean;
	AddressSelectView2 addressselect;
	int moveTo;

	LinearLayout morenLine, zuixinLine, zuidiLine, zuigaoLine;
	ImageView morenIv, zuixinIv, zuidiIv, zuigaoIv;
	int paixuFlag = 0;

	ArrayList<MaMaZengFaBuFenLeiBean> maMaZengFaBuFenLeiBean;
	MyDaAdapter myDaAdapter;
	MyZhongAdapter myZhongAdapter;
	MyXiaoAdapter myXiaoAdapter;
	ListView daLv, zhongLv, xiaoLv;

	String cateId = "";
	int pageNO = 1;
	boolean ShangLaflag = false;

	String QUYU = "", LEIMU = "", PAIXU = "19";

	TextView quyuTv, fenleiTv, paixuTv;

	@Override
	public void update(Observable observable, Object data) {
		ResultEntity entity = super.handlerError(data);
		// ByAlert.alert("><" + entity.getData());
		if (entity != null) {
			if (entity.getEventType() == NewMaMaZengPresenter.LiebiaofenyeSuccess) {
				// Log.e("wodeZengSongShangPingBean1",
				// wodeZengSongShangPingBean.getList().size()+"a");
				wodeZengSongShangPingBean = (WodeZengSongShangPingBean) entity
						.getData();

				// Log.e("~~~~", ShangLaflag+"");
				// wodeZengSongShangPingBeanTwo.getList().addAll(wodeZengSongShangPingBean.getList());
				// initGridView(wodeZengSongShangPingBeanTwo);

				Log.e("wodeZengSongShangPingBean2", wodeZengSongShangPingBean
						.getList().size() + "a");
				if (ShangLaflag == true) {
					wodeZengSongShangPingBeanTwo.getList().addAll(
							wodeZengSongShangPingBean.getList());
					Log.e("wodeZengSongShangPingBeanTwo",
							wodeZengSongShangPingBeanTwo.getList().size() + "a");
					adapter.upDate(wodeZengSongShangPingBeanTwo,
							wodeZengSongShangPingBeanTwo.getList().size());

					adapter.notifyDataSetChanged();
					// initGridView(wodeZengSongShangPingBeanTwo);
				} else if (ShangLaflag == false) {
					Log.e("wodeZengSongShangPingBean3",
							wodeZengSongShangPingBean.getList().size() + "");
					initGridView(wodeZengSongShangPingBean);
					// Log.e("wodeZengSongShangPingBean4",
					// wodeZengSongShangPingBean.getList().size()+"");
					wodeZengSongShangPingBeanTwo = wodeZengSongShangPingBean;
					// Log.e("wodeZengSongShangPingBeanTwo",
					// wodeZengSongShangPingBeanTwo.getList().size()+"");
				}

			} else if (entity.getEventType() == NewMaMaZengPresenter.LiebiaofenyeFail) {

			}
			if (entity.getEventType() == NewMaMaZengPresenter.LeimubufenyeSuccess) {
				maMaZengFaBuFenLeiBean = (ArrayList<MaMaZengFaBuFenLeiBean>) entity
						.getData();
				// wodeZengSongShangPingBean.getList().addAll(wodeZengSongShangPingBean.getList());
				// initGridView(wodeZengSongShangPingBean);

			} else if (entity.getEventType() == NewMaMaZengPresenter.LeimubufenyeFail) {

			}

			//
			// if (entity.getEventType() == TieZiPresenter.DianzanSuccess) {
			// ByAlert.alert(entity.getData() + "");
			// newMaMaZengPresenter.getInfo(luntanTieZiBean);
			// } else if (entity.getEventType() == TieZiPresenter.DianzanyeFail)
			// {
			// ByAlert.alert(entity.getData() + "");
			// }
		}
		try {
			closeProgressDialog();
		} catch (Exception e) {
			// TODO: handle exception
		}
	}

	@Override
	public int initView() {
		// TODO Auto-generated method stub
		return R.layout.activity_zengwuxian_list;
	}

	@Override
	public void onMyActivityCreated() {
		showProgressDialog("加载中，请稍后", true);
		// SPUtils.put(getActivity(), null, SpPublicParams.gridlength,"0");
		// tieZiBaoHanReply = new TieZiBaoHanReply();
		wodeZengSongShangPingBean = new WodeZengSongShangPingBean();
		newMaMaZengPresenter = new NewMaMaZengPresenter(this);
		// newMaMaZengPresenter.libiaofenye(name, cate_id, page_no, page_size,
		// order, zone, uid, to_uid);
		newMaMaZengPresenter.libiaofenye("", LEIMU, pageNO + "", "10", PAIXU,
				QUYU, "", "");

		// adapter = new ItemAdapterOne(getActivity(), null,0, this);
		// zengsong_list_gv.setAdapter(adapter);

		// wodeZengSongShangPingBean= new WodeZengSongShangPingBean();
		// adapter = new ItemAdapterOne(getActivity(),
		// wodeZengSongShangPingBean,
		// wodeZengSongShangPingBean.getList().size(), this);

		newMaMaZengPresenter = new NewMaMaZengPresenter(this);
		newMaMaZengPresenter.leimubufenye();
		refresh_view = (PullToRefreshLayout) getActivity().findViewById(
				R.id.refresh_view);
		// !!!应该是这个代码刷新界面
		refresh_view.setOnRefreshListener(new MyListener());
		pageNO = 1;

		zengsong_list_gv = (PullableGridView) getActivity().findViewById(
				R.id.zengsong_list_gv);
		quyuTv.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {

				showPopupQuYuWindow(v);

			}
		});
		fenleiTv.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {

				showPopupFenLeiWindow(v);
			}

		});
		paixuTv.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {

				showPopupPaiXuWindow(v);
			}

		});

		// ZengSongListAdapter adapter = new ZengSongListAdapter(getContext());
		//
		// zengsong_list_gv.setAdapter(adapter);

		// loaderMap.put("page", page + "");
		// loaderMap.put("page_size", PAGE_SIZE + "");
		// initGridView(null);
		// loader = new DataLoaderthree(getActivity());
		// loader.setOnCompletedListerner(this);
		// OnCompletedListerner
		// loader.startLoading(loaderMap);

		zengsong_list_gv.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> parent, View view,
					int position, long id) {
				// TODO Auto-generated method stub
				// if (popupWindow.isShowing()) {
				// popupWindow.dismiss();
				// }
			}
		});

		// luntanTieZiBean = new LuntanTieZiBean();
		// luntanTieZiBean.setUid(SPUtils.get(getActivity(), null,
		// SpPublicParams.UID, "") + "");
		// luntanTieZiBean.setFid("5");
		// luntanTieZiBean.setPage_no("1");

		// newMaMaZengPresenter.libiaofenye("", "", "", "", "", "", "", "");
		pageNO = 1;
		ShangLaflag = false;

	}

	public class MyListener implements OnRefreshListener {

		@Override
		public void onRefresh(final PullToRefreshLayout pullToRefreshLayout) {
			// 下拉刷新操作
			//
			showProgressDialog("加载中，请稍后", true);
			pageNO = 1;
			// newMaMaZengPresenter.libiaofenye(name, cate_id, page_no,
			// page_size, order, zone, uid, to_uid);
			newMaMaZengPresenter.libiaofenye("", LEIMU, pageNO + "", "10",
					PAIXU, QUYU, "", "");

			// 千万别忘了告诉控件刷新完毕了哦！
			ShangLaflag = false;
			pullToRefreshLayout.refreshFinish(PullToRefreshLayout.SUCCEED);
			// }
			// }.sendEmptyMessageDelayed(0, 1500);
		}

		@Override
		public void onLoadMore(final PullToRefreshLayout pullToRefreshLayout) {
			// 加载操作
			// new Handler() {
			// @Override
			// public void handleMessage(Message msg) {
			// newMaMaZengPresenter = new NewMaMaZengPresenter(this);
			showProgressDialog("加载中，请稍后", true);
			pageNO++;
			ShangLaflag = true;
			newMaMaZengPresenter.libiaofenye("", LEIMU, pageNO + "", "10",
					PAIXU, QUYU, "", "");

			// 千万别忘了告诉控件加载完毕了哦！
			pullToRefreshLayout.loadmoreFinish(PullToRefreshLayout.SUCCEED);
			// }
			// }.sendEmptyMessageDelayed(0, 1500);
		}

	}

	private void showPopupQuYuWindow(View view) {

		View contentView = LayoutInflater.from(getContext()).inflate(
				R.layout.fragment_quyu, null);
		addressselect = (AddressSelectView2) contentView
				.findViewById(R.id.addressselect);

		contentView.findViewById(R.id.btn_confirm).setOnClickListener(
				new OnClickListener() {

					@Override
					public void onClick(View v) {
						showProgressDialog("加载中，请稍后", true);
						if (TextUtils.isEmpty(addressselect.getCityName())) {
							QUYU = addressselect.getProvinceNo() + "";
						} else {
							QUYU = addressselect.getCityNo() + "";
						}
						// ByAlert.alert(QUYU);
						ShangLaflag = false;
						// newMaMaZengPresenter.libiaofenye(name, cate_id,
						// page_no,
						// page_size, order, zone, uid, to_uid);
						newMaMaZengPresenter.libiaofenye("", LEIMU, "1", "10",
								PAIXU, QUYU, "", "");
						popupWindow.dismiss();
						quyuTv.setText(addressselect.getProvinceName()
								+ addressselect.getCityName());
					}
				});

		popupWindow = new PopupWindow(contentView, LayoutParams.MATCH_PARENT,
				LayoutParams.WRAP_CONTENT);

		// 一个自定义的布局，作为显示的内容
		popupWindow.setTouchable(true);
		popupWindow.setBackgroundDrawable(new BitmapDrawable());
		popupWindow.setFocusable(true);
		popupWindow.setOutsideTouchable(true);
		popupWindow.showAsDropDown(view);

		// popupWindow.setBackgroundDrawable(new BitmapDrawable());

	}

	private void showPopupFenLeiWindow(View v) {

		// ListView big, little;

		// ListView daLv, zhongLv, xiaoLv;
		View contentView = LayoutInflater.from(getContext()).inflate(
				R.layout.activity_mamazengfabu_fenlei, null);
		popupWindow = new PopupWindow(contentView, LayoutParams.MATCH_PARENT,
				800);

		daLv = (ListView) contentView.findViewById(R.id.daLv);
		zhongLv = (ListView) contentView.findViewById(R.id.zhongLv);
		xiaoLv = (ListView) contentView.findViewById(R.id.xiaoLv);

		myDaAdapter = new MyDaAdapter(maMaZengFaBuFenLeiBean, getActivity());
		daLv.setAdapter(myDaAdapter);
		zhongLv.setVisibility(View.GONE);
		xiaoLv.setVisibility(View.GONE);

		contentView.findViewById(R.id.all).setOnClickListener(
				new OnClickListener() {

					@Override
					public void onClick(View v) {
						showProgressDialog("加载中，请稍后", true);
						// ByAlert.alert("全部分类");
						LEIMU = "";
						ShangLaflag = false;
						newMaMaZengPresenter.libiaofenye("", LEIMU, "1", "10",
								PAIXU, QUYU, "", "");
						popupWindow.dismiss();
						fenleiTv.setText("全部分类");
					}
				});

		popupWindow.setTouchable(true);
		popupWindow.setBackgroundDrawable(new BitmapDrawable());
		popupWindow.setFocusable(true);
		popupWindow.setOutsideTouchable(true);
		popupWindow.showAsDropDown(v);

	}

	private void showPopupPaiXuWindow(View v) {
		// 一个自定义的布局，作为显示的内容

		View contentView = LayoutInflater.from(getContext()).inflate(
				R.layout.fragment_paixu, null);
		morenLine = (LinearLayout) contentView.findViewById(R.id.morenLine);
		morenIv = (ImageView) contentView.findViewById(R.id.morenIv);
		zuixinLine = (LinearLayout) contentView.findViewById(R.id.zuixinLine);
		zuixinIv = (ImageView) contentView.findViewById(R.id.zuixinIv);
		zuidiLine = (LinearLayout) contentView.findViewById(R.id.zuidiLine);
		zuidiIv = (ImageView) contentView.findViewById(R.id.zuidiIv);

		if (paixuFlag == 0) {
			morenIv.setVisibility(View.VISIBLE);
			zuixinIv.setVisibility(View.GONE);
			zuidiIv.setVisibility(View.GONE);

		} else if (paixuFlag == 1) {
			morenIv.setVisibility(View.GONE);
			zuixinIv.setVisibility(View.VISIBLE);
			zuidiIv.setVisibility(View.GONE);

		} else if (paixuFlag == 2) {
			morenIv.setVisibility(View.GONE);
			zuixinIv.setVisibility(View.GONE);
			zuidiIv.setVisibility(View.VISIBLE);

		}

		morenLine.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {

				morenIv.setVisibility(View.VISIBLE);
				zuixinIv.setVisibility(View.GONE);
				zuidiIv.setVisibility(View.GONE);
				showProgressDialog("加载中，请稍后", true);
				paixuFlag = 0;
				// newMaMaZengPresenter.libiaofenye(name, cate_id, page_no,
				// page_size, order, zone, uid, to_uid);
				PAIXU = "19";

				// newMaMaZengPresenter.libiaofenye(name, cate_id, page_no,
				// page_size, order, zone, uid, to_uid);
				ShangLaflag = false;
				newMaMaZengPresenter.libiaofenye("", LEIMU, "1", "10", PAIXU,
						QUYU, "", "");
				paixuTv.setText("默认排序");
				popupWindow.dismiss();

			}

		});
		zuixinLine.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				morenIv.setVisibility(View.GONE);
				zuixinIv.setVisibility(View.VISIBLE);
				zuidiIv.setVisibility(View.GONE);

				showProgressDialog("加载中，请稍后", true);
				paixuFlag = 1;
				// newMaMaZengPresenter.libiaofenye(name, cate_id, page_no,
				// page_size, order, zone, uid, to_uid);
				PAIXU = "19";

				// newMaMaZengPresenter.libiaofenye(name, cate_id, page_no,
				// page_size, order, zone, uid, to_uid);
				ShangLaflag = false;
				newMaMaZengPresenter.libiaofenye("", LEIMU, "1", "10", PAIXU,
						QUYU, "", "");

				popupWindow.dismiss();
				paixuTv.setText("最新排序");

			}
		});
		zuidiLine.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				morenIv.setVisibility(View.GONE);
				zuixinIv.setVisibility(View.GONE);
				zuidiIv.setVisibility(View.VISIBLE);

				showProgressDialog("加载中，请稍后", true);
				paixuFlag = 2;
				// newMaMaZengPresenter.libiaofenye(name, cate_id, page_no,
				// page_size, order, zone, uid, to_uid);
				PAIXU = "18";
				ShangLaflag = false;

				newMaMaZengPresenter.libiaofenye("", LEIMU, "1", "10", PAIXU,
						QUYU, "", "");

				popupWindow.dismiss();
				paixuTv.setText("人气商品");

			}
		});

		popupWindow = new PopupWindow(contentView, LayoutParams.MATCH_PARENT,
				LayoutParams.WRAP_CONTENT);
		popupWindow.setBackgroundDrawable(new BitmapDrawable());
		popupWindow.setFocusable(true);
		popupWindow.setTouchable(true);
		popupWindow.setOutsideTouchable(true);
		popupWindow.showAsDropDown(v);

	}

	private void moren() {
		// TODO Auto-generated method stub

	}

	// @Override
	// public void onClick(View v) {
	// switch (v.getId()) {
	// case R.id.foot_view_layout:
	// if (adapter != null && adapter.getFooterView().getStatus() ==
	// FooterViewtwo.MORE) {
	// loadMoreData();
	// }
	// break;
	// case R.id.footview_button:
	// loadMoreData();
	// break;
	// }
	//
	// }
	//
	// /**
	// * 加载下个页码的数据
	// */
	// private void loadMoreData() {
	// if (loader != null) {
	//
	// page = page + 1;
	// loaderMap.put("page", page + "");
	// if (adapter != null) {
	// adapter.setFooterViewStatus(FooterViewtwo.LOADING);
	// }
	//
	// loader.startLoading(loaderMap);
	// }
	// }

	/**
	 * 实例化控件及数据
	 */
	private void initGridView(
			WodeZengSongShangPingBean wodeZengSongShangPingBean) {

		// int gridlength = Integer.parseInt((String) SPUtils.get(getActivity(),
		// null, SpPublicParams.gridlength,""))+4 ;
		// SPUtils.put(getActivity(), null,
		// SpPublicParams.gridlength,gridlength+"");
		// ItemAdapterOne adapter;

		adapter = new ItemAdapterOne(getActivity(), wodeZengSongShangPingBean,
				wodeZengSongShangPingBean.getList().size(), this);

		adapter.notifyDataSetChanged();
		zengsong_list_gv.setAdapter(adapter);

	
		// zengsong_list_gv.setOnItemClickListener(new OnItemClickListener() {
		//
		// @Override
		// public void onItemClick(AdapterView<?> parent, View view, int
		// position, long id) {
		// // Toast.makeText(getActivity(),
		// // " Click on " + parent.getAdapter().getItemId(position),
		// // Toast.LENGTH_SHORT).show();
		// if (position == 0) {
		// Intent intent = new Intent(getActivity(),
		// ActivityZengWuXianYouKe.class);
		// startActivity(intent);
		// ByAlert.alert("假装跳转了游客详情页面。~");
		// } else if (position == 1) {
		// Intent intent = new Intent(getActivity(),
		// ActivityZengWuXianShouZengFang.class);
		// startActivity(intent);
		// ByAlert.alert("假装跳转了受赠方详情页面。~");
		// } else if (position == 2) {
		// Intent intent = new Intent(getActivity(),
		// ActivityZengWuXianZengSongFang.class);
		// startActivity(intent);
		// ByAlert.alert("假装跳转了赠送方页面。~");
		// } else {
		// ByAlert.alert("假装跳转了未知页面。~");
		// }
		// }
		// });

		zengsong_list_gv.smoothScrollToPosition(moveTo);

		// if (tieZiBaoHanReply != null) {

		// adapter.setOnFooterViewClickListener(this);
		// zengsong_list_gv.setAdapter(adapter);
		// zengsong_list_gv.setOnScrollListener(new OnScrollListener() {
		//
		// @Override
		// public void onScrollStateChanged(AbsListView view, int
		// scrollState) {
		// // 滚动到底部自动加载(很重要)
		// if (scrollState == OnScrollListener.SCROLL_STATE_IDLE) {
		// if (view.getLastVisiblePosition() == (view.getCount() - 1) &&
		// !isLoadFinished
		// && adapter.getFooterView().getStatus() != FooterViewtwo.LOADING)
		// {
		// loadMoreData();// 加载数据
		//
		// }
		// }
		//
		// }
		//
		// @Override
		// public void onScroll(AbsListView view, int firstVisibleItem, int
		// visibleItemCount, int totalItemCount) {
		//
		// }
		// });
	}

	@Override
	public void onClick(View v) {
		// String tid = v.getTag(R.id.tag_first) + "";
		// String isLike = v.getTag(R.id.tag_second) + "";
		// String uid = SPUtils.get(getActivity(), null, SpPublicParams.UID, "")
		// + "";
		// if ("0".equals(isLike)) {
		// // showProgressDialog("请求提交中，请稍后", true);
		//
		// //newMaMaZengPresenter.dianzan(uid, "1", tid);
		// // zengsong_list_gv.setSelection((int) v.getTag(R.id.tag_third));
		// moveTo = (int) v.getTag(R.id.tag_third);
		// zengsong_list_gv.smoothScrollToPosition(moveTo);
		// } else {
		// ByAlert.alert("已经点过赞了");
		//
		// }

	}

	// @Override
	// public void onCompletedSucceed(List<String> l) {
	//
	// // 在添加数据之前删除最后的伪造item
	// if (adapter.isFooterViewEnable()) {
	// list.remove(list.get(list.size() - 1));
	// }
	//
	// // 分页加载
	// if (l.size() < PAGE_SIZE || list.size() + l.size() == COUNT) {
	// // 如果加载出来的数目小于指定条数，可视为已全部加载完成
	// isLoadFinished = true;
	// list.addAll(l);
	// adapter.setFootreViewEnable(false);
	// adapter.notifyDataSetChanged();
	// Toast.makeText(getActivity(), "数据加载完毕...一共加载了" + COUNT + "条数据",
	// 0).show();
	// } else {
	// // 还有数据可加载。
	// list.addAll(l);
	// // 伪造一个空项来构造一个footerview;
	// list.add(null);
	// adapter.setFootreViewEnable(true);
	// adapter.notifyDataSetChanged();
	// }
	//
	// }
	//
	// @Override
	// public void onCompletedFailed(String str) {
	// // Toast.makeText(getActivity(), "出错啦！", Toast.LENGTH_LONG).show();
	// ByAlert.alert("加载出错了...");
	//
	// }
	//
	// @Override
	// public void getCount(int count) {
	// // TODO Auto-generated method stub
	// ByAlert.alert("返回多少条数据");
	// }
	// 最左边的listview的adapter
	public class MyDaAdapter extends BaseAdapter {
		ArrayList<MaMaZengFaBuFenLeiBean> maMaZengFaBuFenLeiBean;
		Context context;

		public MyDaAdapter() {
			super();
		}

		public MyDaAdapter(
				ArrayList<MaMaZengFaBuFenLeiBean> maMaZengFaBuFenLeiBean,
				Context context) {
			this.maMaZengFaBuFenLeiBean = maMaZengFaBuFenLeiBean;
			this.context = context;
		}

		@Override
		public int getCount() {
			return maMaZengFaBuFenLeiBean != null ? maMaZengFaBuFenLeiBean
					.size() : 0;
		}

		@Override
		public Object getItem(int position) {
			return maMaZengFaBuFenLeiBean != null ? maMaZengFaBuFenLeiBean
					.get(position) : null;
		}

		@Override
		public long getItemId(int position) {
			return position;
		}

		@Override
		public View getView(final int position, View convertView,
				ViewGroup parent) {
			ViewHolder holder;
			if (convertView == null) {
				holder = new ViewHolder();
				convertView = LayoutInflater.from(context).inflate(
						R.layout.item_mamazeng_fabu_fenlei, null);
				holder.tv = (TextView) convertView.findViewById(R.id.tv);
				holder.line = (LinearLayout) convertView
						.findViewById(R.id.line);
				convertView.setTag(holder);
			} else {
				holder = (ViewHolder) convertView.getTag();
			}

			holder.tv.setText(maMaZengFaBuFenLeiBean.get(position).getName());

			holder.line.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {

					if (maMaZengFaBuFenLeiBean.get(position) != null
							&& maMaZengFaBuFenLeiBean.get(position).getChild()
									.size() > 0) {
						myZhongAdapter = new MyZhongAdapter(
								maMaZengFaBuFenLeiBean, context, position);
						zhongLv.setVisibility(View.VISIBLE);
						if (myZhongAdapter != null) {
							zhongLv.setAdapter(myZhongAdapter);
						}
					} else {
						LEIMU = maMaZengFaBuFenLeiBean.get(position).getId();
						// ByAlert.alert(maMaZengFaBuFenLeiBean.get(position)
						// .getName());
						// newMaMaZengPresenter.libiaofenye("", "", "1", "10",
						// "18", "", "", "");
						showProgressDialog("加载中，请稍后", true);
						ShangLaflag = false;
						newMaMaZengPresenter.libiaofenye("", LEIMU, "1", "10",
								PAIXU, QUYU, "", "");
						popupWindow.dismiss();
						fenleiTv.setText(maMaZengFaBuFenLeiBean.get(position)
								.getName());

					}

				}
			});
			return convertView;

		}
	}

	// 中间的listview的adpter
	class MyZhongAdapter extends BaseAdapter {
		ArrayList<MaMaZengFaBuFenLeiBean> entity;
		Context context;
		int daPosition;

		public MyZhongAdapter() {
			super();
		}

		public MyZhongAdapter(ArrayList<MaMaZengFaBuFenLeiBean> entity,
				Context context, int daPosition) {
			super();
			this.entity = entity;
			this.context = context;
			this.daPosition = daPosition;
		}

		@Override
		public int getCount() {
			return entity != null ? entity.get(daPosition).getChild().size()
					: 0;
		}

		@Override
		public Object getItem(int position) {
			return entity != null ? entity.get(daPosition).getChild()
					.get(position) : null;
		}

		@Override
		public long getItemId(int position) {
			return position;
		}

		@Override
		public View getView(final int position, View convertView,
				ViewGroup parent) {
			ViewHolder holder;
			if (convertView == null) {
				holder = new ViewHolder();
				convertView = LayoutInflater.from(context).inflate(
						R.layout.item_mamazeng_fabu_fenlei, null);
				holder.tv = (TextView) convertView.findViewById(R.id.tv);
				holder.line = (LinearLayout) convertView
						.findViewById(R.id.line);
				convertView.setTag(holder);
			} else {
				holder = (ViewHolder) convertView.getTag();
			}

			holder.tv.setText(entity.get(daPosition).getChild().get(position)
					.getName());
			holder.line.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {

					if (entity.get(daPosition).getChild().get(position)
							.getChild() != null
							&& entity.get(daPosition).getChild().get(position)
									.getChild().size() > 0) {
						myXiaoAdapter = new MyXiaoAdapter(entity
								.get(daPosition).getChild().get(position),
								context, daPosition, position);
						xiaoLv.setAdapter(myXiaoAdapter);
						xiaoLv.setVisibility(View.VISIBLE);

					} else {
						showProgressDialog("加载中，请稍后", true);
						ShangLaflag = false;
						// ByAlert.alert(maMaZengFaBuFenLeiBean.get(daPosition)
						// .getName()
						// + maMaZengFaBuFenLeiBean.get(daPosition)
						// .getChild().get(position).getName());
						LEIMU = maMaZengFaBuFenLeiBean.get(daPosition)
								.getChild().get(position).getId();
						newMaMaZengPresenter.libiaofenye("", LEIMU, "1", "10",
								PAIXU, QUYU, "", "");
						popupWindow.dismiss();
						fenleiTv.setText(maMaZengFaBuFenLeiBean.get(daPosition)
								.getChild().get(position).getName());
					}

				}
			});
			return convertView;
		}

	}

	// 最右边的listView的Adpter
	class MyXiaoAdapter extends BaseAdapter {
		MaMaZengFaBuFenLeiBean.B entity;
		private LayoutInflater inflater;
		Context context;
		int bigPosition, zhongPosition;

		public MyXiaoAdapter() {
			super();
		}

		public MyXiaoAdapter(MaMaZengFaBuFenLeiBean.B entity, Context context,
				int bigPosition, int zhongPosition) {
			super();
			this.entity = entity;
			this.context = context;
			this.bigPosition = bigPosition;
			this.zhongPosition = zhongPosition;
		}

		@Override
		public int getCount() {
			return entity.getChild() != null ? entity.getChild().size() : 0;
		}

		@Override
		public Object getItem(int position) {
			// TODO Auto-generated method stub
			return entity.getChild() != null ? entity.getChild().get(position)
					: null;
		}

		@Override
		public long getItemId(int position) {
			// TODO Auto-generated method stub
			return position;
		}

		@Override
		public View getView(final int position, View convertView,
				ViewGroup parent) {
			ViewHolder holder;
			if (convertView == null) {
				holder = new ViewHolder();
				convertView = LayoutInflater.from(context).inflate(
						R.layout.item_mamazeng_fabu_fenlei, null);
				holder.tv = (TextView) convertView.findViewById(R.id.tv);
				holder.line = (LinearLayout) convertView
						.findViewById(R.id.line);
				convertView.setTag(holder);
			} else {
				holder = (ViewHolder) convertView.getTag();
			}

			holder.tv.setText(entity.getChild().get(position).getName());
			holder.line.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					showProgressDialog("加载中，请稍后", true);
					ShangLaflag = false;
					// ByAlert.alert(maMaZengFaBuFenLeiBean.get(bigPosition)
					// .getName()
					// + maMaZengFaBuFenLeiBean.get(bigPosition)
					// .getChild().get(zhongPosition).getName()
					// + maMaZengFaBuFenLeiBean.get(bigPosition)
					// .getChild().get(zhongPosition).getChild()
					// .get(position).getName());
					LEIMU = maMaZengFaBuFenLeiBean.get(bigPosition).getChild()
							.get(zhongPosition).getChild().get(position)
							.getId();
					newMaMaZengPresenter.libiaofenye("", LEIMU, "1", "10",
							PAIXU, QUYU, "", "");
					popupWindow.dismiss();
					fenleiTv.setText(maMaZengFaBuFenLeiBean.get(bigPosition)
							.getChild().get(zhongPosition).getChild()
							.get(position).getName());
				}
			});

			return convertView;
		}

	}

	class ViewHolder {

		public TextView tv;
		public LinearLayout line;
	}

}
